import {createStore} from "vuex";

import VuexPersistence from "vuex-persist";

import message from '@/store/08_modules/message'

const vuexLocal = new VuexPersistence({
    storage: window.localStorage,

    reducer:(state)=>{
        return {
            count:state.count
        }
    }
})


const store = createStore({
    state:{
        count:0,
        'msg':'hello'
    },
    mutations:{
        change(state,payload){
            state.count += payload
        }
    },
    actions:{
        change(context,payload){
            setTimeout(()=>{
                context.commit('change',payload)
            },2000)
        }
    },
    getters:{
        doubleCount(state){
            return state.count * 2
        }
    },
    plugins:[vuexLocal.plugin],

    //引入模块
    modules:{
        message
    }
})

export default store